<?php

namespace App\Model;

use App\Http\Controllers\Constant\Constant;
use Illuminate\Database\Eloquent\Model;

/**
 * @property integer $id
 * @property string $title
 * @property float $money
 * @property float $jsmoney
 * @property float $limitMoney
 * @property integer $is_del
 * @property string $created_at
 * @property string $updated_at
 * @property integer $is_js
 * @property string $desc
 * @property integer $paytype
 */
class OAProjectYsDetail extends Model
{
    protected $table = 'project_ys_dtail';

    public $timestamps = true;

    protected $fillable = [
        'xmid', 'ysid', 'title',
        'money', 'jsmoney', 'paytype',
        'is_del','desc','created_at',
        'updated_at','is_js'
    ];

    public static function getLimitMoney($xmid,$paytype,$title='')
    {
       return OAProjectYsDetail::query()
            ->where('xmid',$xmid)
            ->where('paytype',$paytype)
            ->when($title,function ($q) use ($title){
                return  $q->where('id', $title);
            })
            ->value('money');
    }

    public function ys()
    {
        return $this->belongsTo(OAProjectYs::class,'ysid','id');
    }

    public function getLimitMoneyAttribute()
    {
        return $this->jsmoney > 0 ? $this->jsmoney :  $this->money;
    }

}
